home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
-
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: April 15 1998.
- // Author: rs
- //
- // Description:
- // This script returns the active camera view direction as a float[]. The
- // vector is normalized.
- //
-
- global proc float[] nurbsViewDirectionVector( int $onlyOrtho )
- //
- // Description :
- // Get the current camera view direction as a normalized vector.
- // If $onlyOrtho flag is set to true, this is done for the orthogonal
- // cameras only; the perspective cameras get the default up direction
- // returned as the result.
- //
- {
- float $result[];
-
- string $isitYup = `upAxis -q -ax`;
- if( "y" == $isitYup ) {
- $result[0] = 0.0 ;
- $result[1] = 1.0 ;
- $result[2] = 0.0 ;
- }
- else {
- $result[0] = 0.0 ;
- $result[1] = 0.0 ;
- $result[2] = 1.0 ;
- }
-
- string $forTheWarning = "Failed to compute active camera view direction." +
- " Using the default (" + $result[0] + "," +
- $result[1] + "," + $result[2] + ")";
-
- // get the current camera view.
- //
- string $cameraName ;
- if( catch( $cameraName = `lookThru -q` ) ) {
- warning $forTheWarning;
- return $result ;
- }
-
- if( $onlyOrtho && !`camera -q -o $cameraName` ) {
- // Don't do anything for perspective cameras...
- return $result;
- }
-
- float $coiDistance = 0.0 ;
- if( catch( $coiDistance = `camera -q -coi $cameraName` )) {
- warning $forTheWarning;
- return $result ;
- }
-
- // save the selection list because createNode changes it.
- // Later, we need this to restore the selection list.
- string $selectionList[] = `ls -sl`;
-
- string $ppm ;
- if( catch($ppm = `createNode pointMatrixMult`) ) {
- warning $forTheWarning;
- select -r $selectionList;
- return $result ;
- }
-
- // restore the selection list
- //
- select -r $selectionList;
-
- // compute the view direction.
- //
- setAttr ($ppm +".inPoint") -type double3 0.0 0.0 (-$coiDistance) ;
- setAttr ($ppm +".vectorMultiply") true ;
- connectAttr ($cameraName+".worldMatrix[0]") ($ppm+".inMatrix") ;
- float $coi[] = `getAttr ($ppm+".output")` ;
- delete $ppm ;
-
- // fill up the result.
- //
- int $i ;
- float $sum = 0;
- for( $i = 0 ; $i < 3 ; $i++ ) {
- $sum += ($coi[$i] * $coi[$i]);
- $result[$i] = $coi[$i];
- }
-
- if( $sum > 0 ) {
- $sum = -1.0/sqrt($sum);
- for( $i = 0 ; $i < 3 ; $i++ ) {
- $result[$i] = $result[$i] * $sum;
- }
- }
- return $result ;
- }
-
-